﻿namespace Vdc.Interface
{
    using System;
    using System.Collections;
    using System.Web.UI.WebControls;

    internal class VdcCloner
    {
        internal static Button CloneButton(Button button)
        {
            Button button2 = new Button {
                AccessKey = button.AccessKey,
                CausesValidation = button.CausesValidation,
                CssClass = button.CssClass,
                Enabled = button.Enabled,
                EnableTheming = button.EnableTheming,
                EnableViewState = button.EnableViewState,
                SkinID = button.SkinID,
                TabIndex = button.TabIndex,
                TemplateControl = button.TemplateControl,
                Text = button.Text,
                ToolTip = button.ToolTip,
                ValidationGroup = button.ValidationGroup,
                Visible = button.Visible,
                CommandName = button.CommandName,
                CommandArgument = button.CommandArgument,
                UseSubmitBehavior = button.UseSubmitBehavior,
                PostBackUrl = button.PostBackUrl,
                //CausesValidation = button.CausesValidation,
                //ValidationGroup = button.ValidationGroup,
                OnClientClick = button.OnClientClick
            };
            IEnumerator enumerator = button.Attributes.Keys.GetEnumerator();
            while (enumerator.MoveNext())
            {
                string current = (string) enumerator.Current;
                button2.Attributes[current] = button.Attributes[current];
            }
            return button2;
        }

        internal static CheckBox CloneCheckBox(CheckBox chk1)
        {
            CheckBox box = new CheckBox {
                AccessKey = chk1.AccessKey,
                AutoPostBack = chk1.AutoPostBack,
                CausesValidation = chk1.CausesValidation,
                Checked = chk1.Checked,
                Enabled = chk1.Enabled,
                EnableViewState = chk1.EnableViewState,
                Height = chk1.Height,
                TabIndex = chk1.TabIndex,
                Text = chk1.Text,
                TextAlign = chk1.TextAlign,
                ToolTip = chk1.ToolTip,
                ValidationGroup = chk1.ValidationGroup,
                Visible = chk1.Visible
            };
            IEnumerator enumerator = chk1.Attributes.Keys.GetEnumerator();
            while (enumerator.MoveNext())
            {
                string current = (string) enumerator.Current;
                box.Attributes[current] = chk1.Attributes[current];
            }
            return box;
        }

        internal static TextBox CloneDropDownListToTextBox(DropDownList ddl)
        {
            return new TextBox { AccessKey = ddl.AccessKey, AutoPostBack = ddl.AutoPostBack, CausesValidation = ddl.CausesValidation, CssClass = ddl.CssClass, Enabled = ddl.Enabled, EnableTheming = ddl.EnableTheming, EnableViewState = ddl.EnableViewState, SkinID = ddl.SkinID, TabIndex = ddl.TabIndex, TemplateControl = ddl.TemplateControl, ToolTip = ddl.ToolTip, ValidationGroup = ddl.ValidationGroup, Visible = ddl.Visible };
        }

        internal static RadioButton CloneRadioButton(RadioButton rdbtn1)
        {
            RadioButton button = new RadioButton {
                AccessKey = rdbtn1.AccessKey,
                AutoPostBack = rdbtn1.AutoPostBack,
                CausesValidation = rdbtn1.CausesValidation,
                Checked = rdbtn1.Checked,
                Enabled = rdbtn1.Enabled,
                EnableViewState = rdbtn1.EnableViewState,
                GroupName = rdbtn1.GroupName,
                Height = rdbtn1.Height,
                TabIndex = rdbtn1.TabIndex,
                Text = rdbtn1.Text,
                TextAlign = rdbtn1.TextAlign,
                ToolTip = rdbtn1.ToolTip,
                ValidationGroup = rdbtn1.ValidationGroup,
                Visible = rdbtn1.Visible
            };
            IEnumerator enumerator = rdbtn1.Attributes.Keys.GetEnumerator();
            while (enumerator.MoveNext())
            {
                string current = (string) enumerator.Current;
                button.Attributes[current] = rdbtn1.Attributes[current];
            }
            return button;
        }

        internal static TextBox CloneTextBox(TextBox textBox)
        {
            TextBox box = new TextBox {
                AccessKey = textBox.AccessKey,
                AutoCompleteType = textBox.AutoCompleteType,
                AutoPostBack = textBox.AutoPostBack,
                CausesValidation = textBox.CausesValidation,
                Columns = textBox.Columns,
                CssClass = textBox.CssClass,
                Enabled = textBox.Enabled,
                EnableTheming = textBox.EnableTheming,
                EnableViewState = textBox.EnableViewState,
                MaxLength = textBox.MaxLength,
                ReadOnly = textBox.ReadOnly,
                Rows = textBox.Rows,
                SkinID = textBox.SkinID,
                TabIndex = textBox.TabIndex,
                TemplateControl = textBox.TemplateControl,
                Text = textBox.Text,
                TextMode = textBox.TextMode,
                ToolTip = textBox.ToolTip,
                ValidationGroup = textBox.ValidationGroup,
                Visible = textBox.Visible,
                Wrap = textBox.Wrap
            };
            if (box.AutoCompleteType == AutoCompleteType.Disabled)
            {
                box.Attributes["autocomplete"] = "off";
            }
            IEnumerator enumerator = textBox.Attributes.Keys.GetEnumerator();
            while (enumerator.MoveNext())
            {
                string current = (string) enumerator.Current;
                box.Attributes[current] = textBox.Attributes[current];
            }
            return box;
        }
    }
}

